package ink.lovejinhu.leetcodeMatch;

/**
 * @author jinhu
 * created 2021-07-25 10:32
 */
public class Solution_5823 {
    public int getLucky(String s, int k) {
        char[] chars = s.toCharArray();
        int[] charsReplice = new int[chars.length];
        for (int i = 0; i < chars.length; i++) {
            charsReplice[i] = chars[i] - 'a' + 1;
        }
        int res01 = 0;
        for (int i = 0; i < charsReplice.length; i++) {
            int shi = charsReplice[i] / 10;
            int ge = charsReplice[i] % 10;
            res01 = res01 + shi + ge;
        }
        int res0k = 0;
        if (k <= 1) {
            return res01;
        } else {
            k = k - 1;
            while (k > 0) {
                int bai = res01 / 100;
                int shi = 0;
                int ge = 0;
                if (bai >= 1) {
                    res01 = res01 % 100;
                    shi = res01 / 10;
                    ge = res01 % 10;
                } else {
                    shi = res01 / 10;
                    ge = res01 % 10;
                }
                res0k = bai + shi + ge;
                res01 = res0k;
                k--;

            }
        }

        return res0k;
    }
}
